package com.pure.common.singleton;

import lombok.Data;

/**
 * @description: enum 天然单例，JVM 保证了枚举是天然的单例，并且不存在线程安全问题，此外还支持序列化。
 * @date: 2022-11-09 16:26
 * @since 1.2.0
 **/
public enum SingletonEnum {

    INSTANCE;

    private Student instance;

    SingletonEnum() {
        instance = new Student();
    }

    public void doSomething() {
        System.out.println("doSomething");
    }

    public Student getInstance() {
        return instance;
    }
}

@Data
class Student {

    private String name;
    private int age;
    private Double availableAmount;

    public Student() {
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", availableAmount=" + availableAmount +
                '}';
    }
}
